package com.qhgrain.api.menurolepermission.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.pubframework.springmybatis.dao.IMysqlBaseMapper;
import com.qhgrain.api.menurolepermission.entity.Role;
import com.qhgrain.api.menurolepermission.info.RoleInfo;

public interface RoleMapper extends IMysqlBaseMapper<Role>{

	@Select("select r.id,r.name,r.type,r.role_code roleCode "
			+ " from base_role r "
			+ " join base_user_role u on u.role_id = r.id "
			+ " where u.user_id = #{userId} "
			+ " and r.status = 0 "
			+ " ")
	List<Role> queryByUser(@Param("userId")String userId);
	
	void insertBatch(List<RoleInfo> list);
	
	void updateByInfo(RoleInfo info);
	
	@Select("select r.id ,r.`name`,r.role_code roleCode,r.type type,r.`status`\n" +
			"from base_role r \n" +
			"join base_role_application ra on ra.role_id = r.id\n" +
			"join base_application a on a.id = ra.application_id \n" +
			"where r.`status` = '0'\n" +
			"  and a.id = #{appId}")
	List<RoleInfo> getRolesByAppId(@Param("appId") String appId);
}
